﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.t212Menu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void t212_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            t212Mgr mgr = new t212Mgr();
            e.Total = int.Parse(mgr.GetRecordCount_t212(e.Parameters[t212_Filter.ParamPrefix]));
            IList<t212> list = mgr.FindAllByPage_t212(e.Start.ToString(), e.Limit.ToString(), e.Parameters[t212_Filter.ParamPrefix]);
            t212_MainStore.DataSource = list;
            t212_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            t212Mgr mgr = new t212Mgr();
            RowSelectionModel sm = t212_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                t212 _t212 = new t212();
                _t212.t204_00 = row.RecordID;//int.Parse(row.RecordID);
                if (mgr.Del_t212(_t212))
                {
                    log.Debug("t212中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            t212_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            t212Mgr mgr = new t212Mgr();
            t212 _t212 = new t212();
            if (Hid.Text.Length > 0)
                _t212 = mgr.FindById_t212(int.Parse(Hid.Text));
            
			_t212.t204_01 = Txtt204_01.Text.Trim();
			_t212.t204_02 = Txtt204_02.Text.Trim();
			_t212.t204_03 = Txtt204_03.Text.Trim();
			_t212.t204_04 = Txtt204_04.Text.Trim();
			_t212.t204_71 = Txtt204_71.Text.Trim();
			_t212.t204_05 = Txtt204_05.Text.Trim();
			_t212.t204_06 = Txtt204_06.Text.Trim();
			_t212.t204_07 = Txtt204_07.Text.Trim();
			_t212.t204_08 = Txtt204_08.Text.Trim();
			_t212.t204_72 = Txtt204_72.Text.Trim();
			_t212.t204_09 = Txtt204_09.Text.Trim();
			_t212.t204_10 = Txtt204_10.Text.Trim();
			_t212.t204_11 = Txtt204_11.Text.Trim();
			_t212.t204_12 = Txtt204_12.Text.Trim();
			_t212.t204_73 = Txtt204_73.Text.Trim();
			_t212.t204_13 = Txtt204_13.Text.Trim();
			_t212.t204_14 = Txtt204_14.Text.Trim();
			_t212.t204_15 = Txtt204_15.Text.Trim();
			_t212.t204_74 = Txtt204_74.Text.Trim();
			_t212.t204_75 = Txtt204_75.Text.Trim();
			_t212.t204_76 = Txtt204_76.Text.Trim();
			_t212.t204_77 = Txtt204_77.Text.Trim();
			_t212.t204_78 = Txtt204_78.Text.Trim();
			_t212.t204_79 = Txtt204_79.Text.Trim();
			_t212.t204_80 = Txtt204_80.Text.Trim();
			_t212.t204_81 = Txtt204_81.Text.Trim();
			_t212.t204_82 = Txtt204_82.Text.Trim();
			_t212.t204_83 = Txtt204_83.Text.Trim();
			_t212.t204_84 = Txtt204_84.Text.Trim();
			_t212.t204_85 = Txtt204_85.Text.Trim();
			_t212.t204_86 = Txtt204_86.Text.Trim();
			_t212.t204_87 = Txtt204_87.Text.Trim();
			_t212.t204_88 = Txtt204_88.Text.Trim();
			_t212.t204_89 = Txtt204_89.Text.Trim();
			_t212.t204_90 = Txtt204_90.Text.Trim();
			_t212.t204_91 = Txtt204_91.Text.Trim();
			_t212.t204_92 = Txtt204_92.Text.Trim();
			_t212.t204_93 = Txtt204_93.Text.Trim();
			_t212.t204_94 = Txtt204_94.Text.Trim();
			_t212.t204_95 = Txtt204_95.Text.Trim();
			_t212.t204_96 = Txtt204_96.Text.Trim();
			_t212.t204_97 = Txtt204_97.Text.Trim();
			_t212.t204_98 = Txtt204_98.Text.Trim();
			_t212.t204_99 = Txtt204_99.Text.Trim();
			_t212.t204_100 = Txtt204_100.Text.Trim();
			_t212.t204_101 = Txtt204_101.Text.Trim();
			_t212.t204_16 = Txtt204_16.Text.Trim();
			_t212.t204_70 = Txtt204_70.Text.Trim();
			_t212.t204_17 = Txtt204_17.Text.Trim();
			_t212.t204_18 = Txtt204_18.Text.Trim();
			_t212.t204_19 = Txtt204_19.Text.Trim();
			_t212.collection_time = Txtcollection_time.Text.Trim();

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_t212(_t212);
            else
                isok = mgr.Add_t212(_t212);
            if (isok)
            {
                t212_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("t212中执行了保存（插入或修改），并成功");
                t212_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}